#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>

int main(){
    printf("I am a father process, pid: %d, ppid: %d\n", getpid(), getppid());
    pid_t id = fork();
    if(id == 0){
        int cnt = 5;
        while(cnt){
            printf("I am a child process, pid: %d, ppid: %d\n", getpid(), getppid());
            sleep(1);
            //cnt--;
        }
        printf("child quit...\n");
        exit(3);
    }
    sleep(4);
    //pid_t rid = wait(NULL);
    int status = 0;
    pid_t rid = waitpid(id, &status, 0);
    sleep(2);
    if(rid > 0){
        printf("wait sucess!, rid = %d\n", rid);
    }else{
        printf("wait failed!\n");
    }
    printf("father quit...\n");
    printf("status: %d, exit code: %d, exit signal: %d\n", status, (status >> 8) & 0XFF, status & 0X7F);
    return 0;
}
